package com.lieve.bpm.listener;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.TaskListener;

/**
 * @author sunyoboy
 * 2020/10/16
 */
@Slf4j
public class GlobalListener implements TaskListener, ExecutionListener {

    @Override
    public void notify(DelegateExecution execution) throws Exception {
        String eventName = execution.getEventName();
        if ("start".equals(eventName)) {
            log.debug("start=========");
        } else if ("end".equals(eventName)) {
            log.debug("end=========");
        } else if ("take".equals(eventName)) {
            log.debug("take=========");
        }
    }

    /**
     * 任务完成的时候，触发complete事件。任务完成之后，要从ACT_RU_TASK中删除这条记录，所以触发delete事件。
     * @param delegateTask
     */
    @Override
    public void notify(DelegateTask delegateTask) {
        String eventName = delegateTask.getEventName();
        if ("create".endsWith(eventName)) {
            log.debug("create=========");
        } else if ("assignment".endsWith(eventName)) {
            log.debug("assignment========");
        } else if ("complete".endsWith(eventName)) {
            log.debug("complete===========");
        } else if ("delete".endsWith(eventName)) {
            log.debug("delete=============");
        }
    }
}
